package ua.soso.ui.dwr.error;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DwrException extends Exception {
    private static final long serialVersionUID = 1429116786928081341L;

    private final String stringStackTrace;
    private final List<String> messages;

    public DwrException(String message, Throwable cause) {
        super(message, cause);

        StringWriter writer = new StringWriter();

        cause.printStackTrace(new PrintWriter(writer));

        this.stringStackTrace = writer.getBuffer().toString();
        this.messages = Collections.singletonList(message);
    }

    public DwrException(List<String> messages) {
        super("complex");

        this.stringStackTrace = null;
        this.messages = new ArrayList<String>(messages);
    }

    public DwrException(String message) {
        super(message);
        this.stringStackTrace = null;
        this.messages = Collections.singletonList(message);
    }

    public String getStringStackTrace() {
        return stringStackTrace;
    }

    public List<String> getMessages() {
        return messages;
    }
}
